package com.yan.kfgl.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.InitializingBean;

import com.yan.kfgl.model.vo.ShownUser;

public class LoginInterceptor implements MethodInterceptor,InitializingBean {

	@Override
	public void afterPropertiesSet() throws Exception {
		
	}

	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		String result = "login";
		
		HttpServletRequest request = ServletActionContext.getRequest();
		String sessID = request.getSession().getId();
		HttpSession session = request.getSession();
		Map<String, ShownUser> userLogin = (Map<String, ShownUser>) session.getAttribute("userLogin");
		
		if (userLogin != null) {
			ShownUser user = userLogin.get(sessID);
			if(user != null){
				result = (String)invocation.proceed();
			}
		}
		return result;
	}

}
